
<%@ page import="com.webboard.Post" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'post.label', default: 'Post')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
            <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
        </div>
        <div class="body">
            <h1><g:message code="default.show.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="dialog">
                <table>
                    <tbody>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="post.id.label" default="Id" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: postInstance, field: "id")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="post.title.label" default="Title" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: postInstance, field: "title")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="post.username.label" default="Username" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: postInstance, field: "username")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="post.text.label" default="Text" /></td>
                            
                            <td valign="top" class="value">${fieldValue(bean: postInstance, field: "text")}</td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="post.postDate.label" default="Post Date" /></td>
                            
                            <td valign="top" class="value"><g:formatDate date="${postInstance?.postDate}" /></td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="post.reply.label" default="Reply" /></td>
                            
                            <td valign="top" style="text-align: left;" class="value">
                                <ul>
                                <g:each in="${postInstance.reply}" var="r">
                                    <li><g:link controller="reply" action="show" id="${r.id}">${r?.encodeAsHTML()}</g:link></li>
                                </g:each>
                                </ul>
                            </td>
                            
                        </tr>
                    
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="post.user.label" default="User" /></td>
                            
                            <td valign="top" class="value"><g:link controller="user" action="show" id="${postInstance?.user?.id}">${postInstance?.user?.encodeAsHTML()}</g:link></td>
                            
                        </tr>
                    
                    </tbody>
                </table>
            </div>
            <div class="buttons">
              <!--Show List of Reply-->
    <g:each in="${postInstance.reply}" var="r">
    <!--g:each in="${postInstance.listOfId()}" var="r"-->
      <table border="1">
        <tr>
          <td colspan="3">${r?.text}</td>
        </tr>
        <tr>
          <td width="60%">โดย : ${r?.username}</td>
          <td width="25%">[ ${r?.replyDate} ]</td>
          <td width="15%">#ความคิดเห็นที่ ${r?.id}</td>
        <tr>
      </table>
    </g:each>
              <!--End Show List of Reply-->
               <!--ReplyCode-->
      <g:form controller="reply" action="save" >
        <div class="dialog">
          <g:hiddenField name="postId" value="${postInstance.id}"/>
          <table border="1">
            <tbody>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="text"><g:message code="reply.text.label" default="Text" /></label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: replyInstance, field: 'text', 'errors')}">
            <richui:richTextEditor name="text" value="${replyInstance?.text}" />
            </td>
            </tr>

            <tr class="prop">
              <td valign="top" class="name">
                <label for="username"><g:message code="reply.username.label" default="Username" /></label>
              </td>

              <td valign="top" class="value ${hasErrors(bean: replyInstance, field: 'username', 'errors')}">
            <g:isLoggedIn>
              <g:hiddenField name="username" value="${loggedInUserInfo(field:'username')}"/>
              <g:loggedInUserInfo field="username"/>
            </g:isLoggedIn>
            <g:isNotLoggedIn>
              <g:textField style="width: 90%;color: fuchsia; background-color:Black;border: solid red" name="username" value="${replyInstance?.username}" />
            </g:isNotLoggedIn>
            </td>
            </tr>

            </tbody>
          </table>
        </div>
        <div class="buttons">
          <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
        </div>
      </g:form>
      <!-- End of Reply Code -->
                <g:form>
                    <g:hiddenField name="id" value="${postInstance?.id}" />
                    <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
                    <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
                </g:form>
            </div>
        </div>
    </body>
</html>
